package com.injurydetection.www.widget;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.injurydetection.www.R;

/**
 * Created by sunguiyong on 2020/8/27
 */
public class InitPortDialog extends Dialog {
    private String message;
    private boolean canCancel;

    private TextView mTextView;

    public InitPortDialog(@NonNull Context context) {
        super(context);
    }

    public InitPortDialog(@NonNull Context context, int themeResId, String message, boolean canCancel) {
        super(context, themeResId);
//        View view = LayoutInflater.from(context).inflate(R.layout.dialog_export_data, null);
//        setContentView(view);
        this.canCancel = canCancel;
        this.message = message;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_export_data);
        mTextView = findViewById(R.id.textView32);
//        setCancelable(canCancel);
        setCanceledOnTouchOutside(canCancel);
        mTextView.setText(message);
    }

    public void setMessage(String message) {
        this.message = message;
        handler.sendEmptyMessage(0);
    }

    @SuppressLint("HandlerLeak")
    private
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0) {
                mTextView.setText(message);
            }
        }
    };
}
